# Replication archive for: Coppock, Alexander and Seth J. Hill and Lynn Vavreck. 2020. "The Small Effects of Political Advertising are Small Regardless of Context, Message, Sender, or Receiver: Evidence from 59 Real-time Randomized Experiments" Science Advances, forthcoming.

library(tidyverse)
library(estimatr)
library(rmeta)
source("helpers.R")

# figure 2 ----------------------------------------------------------------

favorability_cates <- read_rds("favorability_cates.rds")
vote_choice_cates <- read_rds("vote_choice_cates.rds")

favorability_meta_cates <-
  favorability_cates %>%
  group_by(ad_match, pid_3_pre, pro_democrat) %>%
  do(random_effects_estimator(.)) 

vote_choice_meta_cates <-
  vote_choice_cates %>%
  group_by(ad_match, pid_3_pre, pro_democrat) %>%
  do(random_effects_estimator(.))

gg_df <-
  bind_rows("Favorability" = favorability_meta_cates,
            "Vote choice" = vote_choice_meta_cates,
            .id = "outcome_variable") %>%
  mutate(
    respondent_pid = case_when(
      pid_3_pre == "Democrat" ~ "Democratic respondents",
      pid_3_pre == "Independent" ~ "Independent respondents",
      pid_3_pre == "Republican" ~ "Republican respondents"
    ),
    ad_type = if_else(pro_democrat == 1, "pro-Democratic ad", "pro-Republican ad"),
    se_entry = make_se_entry(estimate, std.error, 3)
  )

g <- 
ggplot(gg_df, aes(estimate, respondent_pid)) +
  geom_vline(xintercept = 0, linetype = "dashed", alpha = 0.5) +
  geom_point() +
  geom_linerange(aes(xmin = conf.low, xmax = conf.high)) +
  geom_text(aes(label = se_entry), nudge_y = 0.3, size = 3) +
  facet_grid(rows = vars(outcome_variable),
             cols = vars(ad_type)) +
  theme_bw() +
  theme(axis.title.y = element_blank(),
        strip.background = element_blank()) +
  xlab("Meta-analytic conditional average treatment effects")

g

